package exam.day26;

import java.util.Arrays;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int p = in.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        int max = 0;
        for(int i = a[0]; i <= a[n-1]; i++) {
            int count = 0;
            for(int j = 0; j < n; j++) {
                if(Math.abs(a[j] - i) <= p) {
                    count++;
                }
            }
            max = Math.max(max, count);
        }
        System.out.println(max);
    }
}
